from faker import Faker
from faker.providers import internet
from faker.providers.credit_card import CreditCard
from faker.providers.credit_card import Provider as credit_card_Provider



class Provider(credit_card_Provider):

    cardPrefixs =['62220238','62178575','62170003',
                  '62226207','62290832','62177107',
                  '52364979','62266612','47206709',
                  '40473977','62255612']

    # def credit_card_number(self, prefix='622202380301'):
    #     return super().credit_card_number(CreditCard(name='工行',prefixes={prefix},length=19))
    # formats = [str(i) + "###########" for i in cardPrefixs()]

    # self.credit_card_types['工行']=('工行', CreditCard('工行', cardPrefixs, 19))

    def bankcard_prefix(self):
        return self.random_element(self.cardPrefixs)

    def bankCard(self,prefix=''):
        if prefix=='':
            preDict={self.bankcard_prefix()}   #self.cardPrefixs
        else:
            preDict={prefix}
        return  self.credit_card_number(CreditCard('银行卡',prefixes=preDict,length=19))
            # prefix+''.join(random.choice("0123456789") for i in range(7))

fake = Faker('zh_CN')
fake.add_provider(internet)
fake.add_provider(Provider)
def fkValue():
    '''
    构造数据
    https://faker.readthedocs.io/en/master/locales/zh_CN.html
    :return:
    '''
    return fake


if __name__ == "__main__":
    #
    fake = fkValue()


    for i in range(2):

        print(fake.phone_number()+":"+fake.ssn(min_age=20,max_age=45)+":"+fake.bankCard('62220238')+":"+fake.name_male())

    print(fake.ipv4_private())
    print(fake.name())
    # fake.add_provider()
    print(fake.credit_card_full(CreditCard(name='工行',prefixes={'62220238'},length=19)))
    print(fake.bankCard())
    print(fake.bankCard('62220238'))
    print(fake.address())
    print(fake.phone_number())
    print(fake.profile())

    xx = fake.ssn(min_age=20, max_age=45)
    print(xx)

    print(int(xx[16])%2)



